module.exports = Player;
const Card = require('./card.js');
function Player(id){
	this._cards = null;
	this._index = [];
	this._pid = id;
	this._history = [];
}

Player.prototype.getName = function() {
	return 'player['+this._pid+']';
}
Player.prototype.setCards = function(cc) {
	console.log('set cards:',cc);
	this._cards = cc;
	this._cards.sort(Card.compare)
}

Player.prototype.play = function(cardInfo) {

	this._history.push(cardInfo);
	//cardInfo = [1,2]
	var a = cardInfo[0];
	var j = a;
	for(var i=1;i<cardInfo.length;i++){
		var b = cardInfo[i];
		console.log('--- ',a,b,j);
		for(j++;j<b;j++){
			console.log(a,'<< ',j);
			this._cards[a++] = this._cards[j];
		}
	}
	var b = this._cards.length;

	for(j++;j<b;j++){
		this._cards[a++] = this._cards[j];
	}

	this._cards.splice(a,this._cards.length-a);
	console.log('剩下的牌:',this._cards);
}

Player.prototype.setDZ = function(dzCard) {
	this._cards = this._cards.concat(dzCard);
}

Player.prototype.sort = function( ) {
	this._cards.sort(Card.compare);
}

Player.prototype.dump = function( ){
	
	var x = []

	for (c in this._cards){
		x.push(this._cards[c].getName())
	}
	return x.join(',')
}


Player.prototype.getCards = function(idxList){
	var cs = [];
	for (i in idxList){
		var idx = idxList[i];
		var card = this._cards[idx];
		cs.push(card);
	}
	return cs;
}

